package com.kgc.dubbo.controller;

import com.github.xiaoymin.knife4j.annotations.Ignore;
import com.kgc.dubbo.service.LocalPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 支付宝支付的controller
 */
@Api(value = "aliPay的controller")
@Controller
@RequestMapping("/api")
public class AliPayController {
    @Autowired
    private LocalPayService localPayService;
    @ApiOperation(value = "支付宝支付的接口",
            httpMethod = "GET",
            protocols = "http",
            notes = "支付宝支付的接口",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="WIDout_trade_no",value = "订单编号",required = true,paramType = "path"),
            @ApiImplicitParam(name ="WIDsubject",value = "支付的主题（这里为商品编号）",required = true,paramType = "path"),
            @ApiImplicitParam(name ="WIDtotal_amount",value = "支付总金额",required = true,paramType = "path"),
    })
    @RequestMapping(value = "/v/pay",method = RequestMethod.GET)
    public void aliPay(String orderId,
                       HttpServletResponse response) throws Exception {
        localPayService.aliPay(orderId,response);
    }
    @Ignore
    @ApiOperation(value = "支付宝的同步通知的处理方法",
            httpMethod = "GET",
            protocols = "http",
            notes = "支付宝的同步通知的处理方法",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @RequestMapping(value="/returnurl",method = RequestMethod.GET)
    public String alipayReturn(HttpServletRequest request) throws Exception {
        String url = localPayService.aliPayReturn(request);
        return "redirect:"+url;
    }
    @Ignore//忽略
    @ApiOperation(value = "支付宝的异步通知的处理方法",
            httpMethod = "POST",
            protocols = "http",
            notes = "支付宝的异步通知的处理方法",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @RequestMapping(value = "/notifyurl",method = RequestMethod.POST)
    public void alipayNotify(HttpServletRequest request,HttpServletResponse response) throws Exception {
        localPayService.aliPayNotify(request,response);
    }

    
}
